package com.wardrobe.soa.backend.booking;

import com.wardrobe.dao.booking.BookingDao;
import com.wardrobe.dao.shop.ShopDao;
import com.wardrobe.domain.booking.BookingBean;
import com.wardrobe.domain.booking.BookingFromBean;
import com.wardrobe.domain.booking.BookingShowBean;
import com.wardrobe.domain.common.BackEndFromBean;
import com.wardrobe.domain.shop.ShopShowBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2018/11/16.
 */
@Service
public class BackBookingService {
    @Autowired
    private BookingDao bookingDao;
    @Autowired
    private ShopDao shopDao;

    public List<BookingShowBean> getBookingList(BookingFromBean fromBean){
        return bookingDao.selectBookingList(fromBean);
    }

    public BookingShowBean getBookingById(long id){
        return bookingDao.selectBookingById(id);
    }

    public int saveBooking(BookingBean bookingBean){
        long shopId = bookingBean.getShopId();
        ShopShowBean shopShowBean = shopDao.selectShopById(shopId);
        if (shopShowBean!=null){
            bookingBean.setLongitude(shopShowBean.getLongitude());
            bookingBean.setLatitude(shopShowBean.getLatitude());
        }
        return bookingDao.insertBooking(bookingBean);
    }

    public int modifyBooking(BackEndFromBean fromBean){
        return bookingDao.updateBooking(fromBean);
    }

    public long countBooking(BookingFromBean fromBean){
        return bookingDao.countBooking(fromBean);
    }
}
